package com.app.TCES.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.app.TCES.domain.Class_Course;
import com.app.TCES.domain.ST_indicators;
import com.app.TCES.domain.TT_indicators;
import com.app.TCES.domain.Teacher_Course;
import com.app.TCES.domain.Test;
import com.app.TCES.service.Teacher_Service;

@Controller
public class Teacher_Controller {

	Logger log = LogManager.getLogger(Teacher_Controller.class);

	@Autowired
	Teacher_Service teacher_Service;

	// 跳转教师课程
	@RequestMapping("/TeacherCourse")
	public String toTeacherCourse(HttpServletRequest request,Model model) {
		
		HttpSession httpSession=request.getSession();
		Object obj = httpSession.getAttribute("userId");
        log.debug(obj);
        List<Class_Course> list = teacher_Service.selectT_Courses(obj);
		model.addAttribute("teacherCourse",list);
		return "/TeacherCourse";
	}

	// 跳转教师查看分数
	@RequestMapping("/TeacherScore")
	public String toTeacherScore(HttpServletRequest request) {

		return "/TeacherScore";
	}

	// 跳转教师同行评价
	@RequestMapping("/TeacherPJ")
	public String toTeacherPJ(HttpServletRequest request,Model model) {
		HttpSession httpSession=request.getSession();
		Object obj = httpSession.getAttribute("userId");
        log.debug(obj);
		List<Teacher_Course> list = teacher_Service.selectTeacher_All(obj);
		model.addAttribute("teachers", list);
		return "/TeacherPJ";
	}

	//获取教师同行评价问题内容
	@ResponseBody
	@RequestMapping("/selectTeacherTest")
	public List<Test> selectTeacherTest(){
		
		return teacher_Service.selectTeacherTest();
	}
	
	//教师同行评分
	@ResponseBody
	@RequestMapping("/insertTT")
	public Map<String , String> insertTT(int teacherId,double score,HttpServletRequest request){
		HttpSession httpSession=request.getSession();
		Object obj = httpSession.getAttribute("userId");
        log.debug(obj);
        teacher_Service.insertTT(teacherId, obj, score);
        
        Map<String, String> map = new HashMap<String, String>();
        map.put("msg", "YES");
        return map;
		
	}
	
	//同过教师查找已评价过的同行(条件:tchId)
	@ResponseBody
	@RequestMapping("/selectIndicators")
	public List<TT_indicators> selectIndicators(HttpServletRequest request){
		
		HttpSession httpSession=request.getSession();
		
		return teacher_Service.selectIndicators(httpSession.getAttribute("userId"));
	}
	
	
	//查看分数(学生评分)
	@ResponseBody
	@RequestMapping("/getScore_Student")
	public Map<String, Object> getScore_Student(HttpServletRequest request) {
		HttpSession httpSession=request.getSession();
		double a=teacher_Service.getScore_Student(httpSession.getAttribute("userId"));
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("score", a);
		return map; 
		
	}
	
	//查看分数(同行评分)
	@ResponseBody
	@RequestMapping("/getScore_Teacher")
	public Map<String, Object> getScore_Teacher(HttpServletRequest request){
		HttpSession httpSession=request.getSession();
		double a=teacher_Service.getScore_Teacher(httpSession.getAttribute("userId"));
		Map<String, Object > map = new HashMap<String, Object>();
		map.put("score", a);
		return map; 
	}
	
	
	//所有分数(学生)
	@ResponseBody
	@RequestMapping("/ScoreAll_student")
	public Map<String, Object> ScoreAll_student(){
		
		
		List<ST_indicators> list = new ArrayList<ST_indicators>();
		Map<String , Object> map = new HashMap<String, Object>();
		list = teacher_Service.getScoreAll_student();
		
		map.put("tol", 1);
		map.put("message", "查询成功");
		map.put("status", 200);
		map.put("list", list);
		
		return map;	
	}
	
	
	//所有分数(同行)
	@ResponseBody
	@RequestMapping("/ScoreAll_teacher")
	public Map<String,Object> ScoreAll_teacher(){
		List<TT_indicators> list = new ArrayList<TT_indicators>();
		list = teacher_Service.getScoreAll_Teacher();
		
		Map<String , Object> map = new HashMap<String, Object>();
		
		map.put("tol", 1);
		map.put("message", "查询成功");
		map.put("status", 200);
		map.put("list", list);
		return map;
	}
	
	//Echarts(student)
	@ResponseBody
	@RequestMapping("/graphS")
	public Map<String, Object> getDataS(){
		int a= teacher_Service.getSATotal();
		int b= teacher_Service.getSBTotal();
		int c= teacher_Service.getSCTotal();
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("a", a);
		map.put("b", b);
		map.put("c", c);
		
		return map;
	}
	
	
	//Echarts(teacher)
	@ResponseBody
	@RequestMapping("/graphT")
	public Map<String, Object> getDataT(){
		int a= teacher_Service.getTATotal();
		int b= teacher_Service.getTBTotal();
		int c= teacher_Service.getTCTotal();
			
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("a", a);
		map.put("b", b);
		map.put("c", c);
			
		return map;
	}
	//Echarts(teacher)
	@ResponseBody
	@RequestMapping("/graphSandT")
	public Map<String, Object> getDataSandT(HttpServletRequest request){
		
		HttpSession httpSession=request.getSession();
		Object obj = httpSession.getAttribute("userId");
        log.debug(obj);
		double a = teacher_Service.getScore_Student(obj);
		double b = teacher_Service.getScore_Teacher(obj);
			
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("a", a);
		map.put("b", b);
		
			
		return map;
	}
	
}
